package com.scse.bms.service;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.scse.bms.domain.UserHeadImgVO;
import com.scse.bms.entity.HeadImgDO;
import com.scse.bms.entity.UserHeadImgDO;
import com.scse.bms.mapper.HeadImgMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @Title: HeadImgServiceImpl
 * @Author: 吴赠禹
 * @Date: 2021/2/27 21:09
 * @Version: 1.0
 * @Description: TODO
 */

@Service
@Transactional(rollbackFor = Exception.class)
public class HeadImgServiceImpl extends ServiceImpl<HeadImgMapper, UserHeadImgVO> implements HeadImgService {


    @Autowired
    private HeadImgMapper headImgMapper;

    /**
     * 获取用户头像
     * @param userId
     * @return
     */
    @Override
    public UserHeadImgVO getHeadImgVOByUserId(Integer userId) {
        return headImgMapper.getHeadImgVOByUserId(userId);
    }


    /**
     * 获取头像列表（分页）
     * @param page
     * @return
     */
    @Override
    public IPage<UserHeadImgVO> getHeadImgVOList(Page<UserHeadImgVO> page) {
        return headImgMapper.getHeadImgVOList(page);
    }


    /**
     * 添加头像
     * @param headImgDO
     * @return
     */
    @Override
    public int addHeadImg(HeadImgDO headImgDO) {
        return headImgMapper.insertHeadImg(headImgDO);
    }


    /**
     * 用户修改头像
     * @return
     */
    @Override
    public List<HeadImgDO> selectHeadImgForUserChose(String src) {
        return headImgMapper.selectHeadImgRandomLimit10(src);
    }


    /**
     * 查询用户是否存在头像
     * @param userId
     * @return
     */
    @Override
    public Integer selectUserIfExistProfile(Integer userId) {
        return headImgMapper.selectUserIfExistProfile(userId);
    }


    /**
     * 为用户添加用户头像关联记录
     * @param userHeadImgDO
     * @return
     */
    @Override
    public int addUserProfile(UserHeadImgDO userHeadImgDO) {
        return headImgMapper.addUserProfile(userHeadImgDO);
    }


    /**
     * 修改用户-头像关联记录
     * @param userHeadImgDO
     * @return
     */
    @Override
    public int updateUserProfile(UserHeadImgDO userHeadImgDO) {
        return headImgMapper.updateUserProfile(userHeadImgDO);
    }
}
